﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Common;
using He.Web.UI;

namespace He.Web.manage.channel
{
    public partial class config : He.Web.UI.Manage
    {
        public int channel_id;
        public Model.channel channel;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["channel_id"] as string, out this.channel_id))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            channel = new He.BLL.channel().GetModel(channel_id);

            if (!Page.IsPostBack)
            {
                chkLoginLevel("setChannel" + channel.id);

                ddlShowEffect.DataSource = GetShowEffectDict(channel.model_id);
                ddlShowEffect.DataTextField = "Value";
                ddlShowEffect.DataValueField = "Key";
                ddlShowEffect.DataBind();

                ShowInfo();
            }
        }

        #region 赋值操作=================================
        private void ShowInfo()
        {
            txtTitle.Text = channel.title;
            txtSubTitle.Text = channel.sub_title;
            ddlOrderBy.SelectedValue = channel.order_by;
            txtPageSize.Text = channel.page_size.ToString();
            txtImgWidth.Text = channel.img_width.ToString();
            txtImgHeight.Text = channel.img_height.ToString();
            ddlListEffect.SelectedValue = channel.list_effect.ToString();
            ddlShowEffect.SelectedValue = channel.show_effect;
            ddlShowComment.SelectedValue = channel.show_comment.ToString();
            ddlCommentAudit.SelectedValue = channel.comment_audit.ToString();
            txtImgUrl.Text = channel.img_url;
            txtSeoKeywords.Text = channel.seo_keywords;
            txtSeoDescription.Text = channel.seo_desc;
        }
        #endregion

        protected void btnSave_Click(object sender, EventArgs e)
        {
            BLL.channel bll = new BLL.channel();
            Model.channel model = bll.GetModel(channel_id);
            model.title = txtTitle.Text.Trim();
            model.sub_title = txtSubTitle.Text.Trim();
            model.order_by = ddlOrderBy.SelectedValue;
            model.page_size = int.Parse(txtPageSize.Text.Trim());
            model.img_width = int.Parse(txtImgWidth.Text.Trim());
            model.img_height = int.Parse(txtImgHeight.Text.Trim());
            model.list_effect = int.Parse(ddlListEffect.SelectedValue);
            model.show_effect = ddlShowEffect.SelectedValue;
            model.show_comment = int.Parse(ddlShowComment.SelectedValue);
            model.comment_audit = int.Parse(ddlCommentAudit.SelectedValue);
            model.img_url = txtImgUrl.Text.Trim();
            //SEO信息
            model.seo_title = "";
            model.seo_keywords = txtSeoKeywords.Text.Trim();
            model.seo_desc = txtSeoDescription.Text.Trim();
            if (!bll.Update(model))
            {
                JscriptPrint("保存过程中发生错误啦！", Request.RawUrl, "Error");
                return;
            }
            RemoveAllCache();
            SaveLogs(string.Format("[{0}管理]修改参数", channel.manage_title));
            JscriptPrint("修改设置成功啦！", Request.RawUrl, "Success");
        }
    }
}